<template>
	<div class="testee_analysis">
		<el-table :data="tableData" stripe style="width: 100%">
			<el-table-column prop="sysUser" label="考生">
				<template slot-scope="{ row }">
					<span>{{ row.sysUser | showUserInfo }}</span>
				</template>
			</el-table-column>
			<el-table-column label="考生得分">
				<template slot-scope="{ row }">
					<p>{{ row.score }}</p>
				</template>
			</el-table-column>
			<el-table-column label="是否及格">
				<template slot-scope="{ row }">
					<el-tag size="medium" type="success" v-if="showPassStatus(row)">及格</el-tag>
					<el-tag size="medium" type="danger" v-else>不及格</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="createTime" label="考试时间" width="180"></el-table-column>

			<el-table-column label="操作" width="120">
				<template slot-scope="{ row }">
					<el-button-group>
						<el-button type="success" size="mini" @click="handleLookAnswer(row)">批阅试卷</el-button>
					</el-button-group>
				</template>
			</el-table-column>
			<div slot="empty" class="emptyBg">
				<el-empty :image-size="100"></el-empty>
			</div>
		</el-table>
		<Pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="getTesteeListData" />
	</div>
</template>

<script>
import moment from 'moment';
export default {
	props: {
		examId: { type: String, default: '' }
	},
	data() {
		return {
			dataCount: 0,
			tableData: [],
			queryData: { page: 1, limit: 10 }
		};
	},
	filters: {
		showUserInfo(data) {
			return data.userName || '';
		}
	},
	watch: {
		examId: {
			handler() {
				this.getTesteeListData();
			},
			immediate: true
		}
	},
	mounted() {
		this.$bus.$on('updateTesteeList', () => {
			this.getTesteeListData();
		});
	},
	beforeDestroy() {
		this.$bus.$off('updateTesteeList');
	},
	methods: {
		//获取考生列表数据
		async getTesteeListData() {
			let params = { ...this.queryData, testExamId: this.examId };
			let result = await this.$store.dispatch('testExamHisQUERY', params);
			if (result.code === '0') {
				let datas = result.data || [];
				this.dataCount = parseInt(result.count);
				this.tableData = datas.map((item) => {
					let time = moment(item.createTime).valueOf();
					return { ...item };
				});
			}
		},

		showPassStatus(data) {
			let gainScore = parseFloat(data.score);
			let passScore = parseFloat(data.testExam.passScore);
			return gainScore >= passScore;
		},

		handleLookAnswer(row) {
			this.$bus.$emit('showExamAnswer', row, 'read');
		}
	}
};
</script>

<style scoped></style>
